Strongly-Typed Events
Lightweight, strongly-typed events, with monitored subscriptions.
- Documentation: API + WiKi.
- Compatible with all existing events - see Extras.
Install
npm i sub-events
Usage
import {SubEvent} from 'sub-events';
const e: SubEvent<string> = new SubEvent();
e.emit('hello');
API: SubEvent, emit
const sub = e.subscribe((data: string) => {
});
sub.cancel();
API: Subscription, subscribe, cancel
Monitoring Subscriptions
Class SubEventCount extends SubEvent with event onCount, to observe the number of subscriptions:
import {SubEventCount, ISubCountChange} from 'sub-events';
const e: SubEventCount<string> = new SubEventCount();
e.onCount.subscribe((info: ISubCountChange) => {
});
const sub = e.subscribe(data => {});
sub.cancel();
API: SubEventCount, onCount
Browser
When including directly from HTML, you can access all types under subEvents
namespace:
<script src="./node_modules/sub-events/dist"></script>
<script>
const e = new subEvents.SubEvent();
e.subscribe(data => {
});
</script>
Note that pre-built script includes only the core library, without the Extras,
which you can bundle yourself as needed.